package org.jeecg.modules.power.shop.service.impl;

import org.jeecg.modules.power.shop.entity.YlShopCollect;
import org.jeecg.modules.power.shop.mapper.YlShopCollectMapper;
import org.jeecg.modules.power.shop.service.IYlShopCollectService;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 门店收藏
 * @Author: jeecg-boot
 * @Date:   2024-07-15
 * @Version: V1.0
 */
@Service
public class YlShopCollectServiceImpl extends ServiceImpl<YlShopCollectMapper, YlShopCollect> implements IYlShopCollectService {

    /**
     * 收藏门店
     * @param shopId
     * @param userId
     */
    public void collect(String shopId,String userId){
        YlShopCollect collect = new YlShopCollect();
        collect.setShopId(shopId);collect.setUserId(userId);
        try{
            this.save(collect);
        }catch (DuplicateKeyException e){
            String info = String.format("用户%s已经收藏门店%s",userId,shopId);
            log.warn(info);
        }
    }

    /**
     * 取消收藏门店
     * @param shopId
     * @param userId
     */
    public void cancel(String shopId,String userId){
        Map param = new HashMap();
        param.put("shop_id",shopId);
        param.put("user_id",userId);
        this.removeByMap(param);
    }

}
